<% layout('/layouts/default.html', {title: '供应链服务协议管理', libs: ['validate','fileupload']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(supplyChainServiceAgreement.isNewRecord ? '新增供应链服务协议' : '编辑供应链服务协议')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${supplyChainServiceAgreement}" action="${ctx}/agreement/supplychainserviceagreement/supplyChainServiceAgreement/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="supplyChainServiceAgreementId"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('协议编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="supplyChainServiceAgreementCode" maxlength="100" class="form-control" placeholder="自动生成" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('签订日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="signDate" readonly="true" maxlength="20" class="form-control laydate required"
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('签订地点')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="signLocation" maxlength="50" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('状态')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="status1" dictType="erp_status" class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('开始日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="startDate" readonly="true" maxlength="20" class="form-control laydate required"
									dataFormat="date" data-type="date" data-done="endDate.click()" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('结束日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="endDate" readonly="true" maxlength="20" class="form-control laydate required"
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd" data-done="checkEndDate()"/>
							</div>
						</div>
					</div>
				</div>
				<div class="form-unit">${text('甲方信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('甲方')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:treeselect id="company" title="${text('公司选择')}"
								path="company.companyCode" labelPath="company.companyName"
								url="${ctx}/sys/company/treeData" canSelectRoot="true" canSelectParent="true"
								class=" required" allowClear="true" callbackFuncName="companyCallback"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('公司地址')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="companyAddress" maxlength="255" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('联系人')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="companyContactPerson" maxlength="100" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('电话')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="companyPhone" maxlength="100" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('邮箱')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="companyEmail" maxlength="100" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('联系人通讯地址')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="companyContactPersonAddr" maxlength="255" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="form-unit">${text('乙方信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('乙方')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:treeselect id="customer" title="${text('乙方选择')}"
								path="customer.customerId" labelPath="customer.customerName"
								url="${ctx}/base/customer/customer/treeData" canSelectRoot="true" canSelectParent="true"
								class=" required" allowClear="true" callbackFuncName="customerCallback"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('公司地址')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerAddress" maxlength="255" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('联系人')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerContactPerson" maxlength="100" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('电话')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerPhone" maxlength="100" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('邮箱')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerEmail" maxlength="100" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('联系人通讯地址')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="customerContactPersonAddr" maxlength="255" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="form-unit">${text('丙方信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('丙方')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="guarantorId" items="${guarantorList}" itemLabel="guarantorName"
								itemValue="guarantorId" class="form-control required" onchange="guarantorChange()" blankOption="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('现住')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="guarantorAddress" maxlength="200" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('电话')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="guarantorPhone" maxlength="100" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('身份证号码')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="guarantorIdNumber" maxlength="100" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('邮箱')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="guarantorEmail" maxlength="100" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注信息')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="form-unit">${text('附件上传')}</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2">
								<span class="required hide">*</span> ${text('附件上传')}：</label>
							<div class="col-sm-10">
								<#form:fileupload id="uploadFile" bizKey="${supplyChainServiceAgreement.id}" bizType="supplyChainServiceAgreement_file"
								uploadType="all" class="" readonly="false" preview="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="form-unit">${text('系统信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('创建者')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<!--<#form:input path="createBy" class="form-control" disabled="true"/>-->
								<#form:select path="createBy" items="${listUser}" disabled="true"
								itemLabel="userName" itemValue="userCode"  blankOption="true" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('创建时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="createDate" class="form-control" readonly="true"
								dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('更新者')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="updateBy" items="${listUser}" disabled="true"
								itemLabel="userName" itemValue="userCode"  blankOption="true" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('更新时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="updateDate" class="form-control" readonly="true"
								dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
				</div>

			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('agreement:supplyChainServiceAgreement:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});

function companyCallback(id, act, index, layero, nodes){
	if (id == 'company'){
		if(act == 'ok'){
			$.ajax({
				type: "POST",
				url: "${ctx}/agreement/supplychainserviceagreement/supplyChainServiceAgreement/getCompanyInfo",
				data: {"companyId": nodes[0].id},
				success: function(data){
					$("#companyAddress").attr("value",data.companyAddress);
					$("#companyContactPerson").attr("value",data.contactPerson);
					$("#companyPhone").attr("value",data.phone);
					$("#companyEmail").attr("value",data.email);
					$("#companyContactPersonAddr").attr("value",data.contactPersonAddr);
				}
			});
		}
		if(act == 'clear'){
			$("#companyAddress").attr("value","");
			$("#companyContactPerson").attr("value","");
			$("#companyPhone").attr("value","");
			$("#companyEmail").attr("value","");
			$("#companyContactPersonAddr").attr("value","");
		}
	}

}

function customerCallback(id, act, index, layero, nodes){
	if (id == 'customer'){
		if(act == 'ok'){
			$.ajax({
				type: "POST",
				url: "${ctx}/agreement/supplychainserviceagreement/supplyChainServiceAgreement/getCustomerInfo",
				data: {"customerId": nodes[0].id},
				success: function(data){
					$("#customerAddress").attr("value",data.address);
					$("#customerContactPerson").attr("value",data.customerContactList[0].contactName);
					$("#customerPhone").attr("value",data.customerContactList[0].phone);
					$("#customerEmail").attr("value",data.customerContactList[0].email);
					$("#customerContactPersonAddr").attr("value",data.customerContactList[0].contactPersonAddr);
					$("#guarantorId").val(data.defaultGuarantor.guarantorId).trigger('change');
					$("#guarantorAddress").attr("value",data.defaultGuarantor.address);
					$("#guarantorPhone").attr("value",data.defaultGuarantor.phone);
					$("#guarantorIdNumber").attr("value",data.defaultGuarantor.idNumber);
					$("#guarantorEmail").attr("value",data.defaultGuarantor.email);
				}
			});
		}
		if(act == 'clear'){
			$("#customerAddress").attr("value","");
			$("#customerContactPerson").attr("value","");
			$("#customerPhone").attr("value","");
			$("#customerEmail").attr("value","");
			$("#customerContactPersonAddr").attr("value","");
			$("#guarantorId").val("").trigger('change');
			$("#guarantorAddress").attr("value","");
			$("#guarantorPhone").attr("value","");
			$("#guarantorIdNumber").attr("value","");
			$("#guarantorEmail").attr("value","");
		}
	}
}
function checkEndDate(){
	let startDate=$("#startDate").val();
	let endDate=$("#endDate").val();
	if(endDate<=startDate){
		$("#endDate").val('');
		js.showErrorMessage("结束日期不能早于开始日期！");
	}
}
function guarantorChange() {
	if ($("#guarantorId").val() != "") {
		$.ajax({
			type: "POST",
			url: "${ctx}/agreement/supplychainserviceagreement/supplyChainServiceAgreement/getGuarantorInfo",
			data: {"guarantorId": $("#guarantorId").val()},
			success: function (data) {
				$("#guarantorIdNumber").attr("value", data.idNumber);
				$("#guarantorAddress").attr("value", data.address);
				$("#guarantorPhone").attr("value", data.phone);
			}
		});
	} else {
		$("#guarantorIdNumber").attr("value","");
		$("#guarantorAddress").attr("value","");
		$("#guarantorPhone").attr("value","");
	}
}
</script>